package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 我的游记 实体类
 *
 * @author pengq
 */
@Setter
@Getter
public class Travel extends BaseDomain {
    /**
     * 一个人
     */
    public static final int PERSON_ONE = 1;
    /**
     * 和父母
     */
    public static final int PERSON_FM = 2;
    /**
     * 和朋友
     */
    public static final int PERSON_PY = 3;
    /**
     * 和同事
     */
    public static final int PERSON_TS = 4;
    /**
     * 和爱人
     */
    public static final int PERSON_AR = 5;
    /**
     * 其他
     */
    public static final int PERSON_QT = 6;

    /**
     * 草稿
     */
    public static final int STATE_DRAFT = 0;
    /**
     * 待审核
     */
    public static final int STATE_PENDING = 1;
    /**
     * 发布
     */
    public static final int STATE_RELEASE = 2;
    /**
     * 拒绝
     */
    public static final int STATE_REFUSE = 3;

    /**
     * 标题
     */
    private String title;
    /**
     * 旅游时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;
    /**
     * 人均收费
     */
    private String perExpends;
    /**
     * 旅游天数
     */
    private Integer days;
    /**
     * 和谁旅游
     */
    private int person;
    /**
     * 作者
     */
    private User author;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
    /**
     * 发布时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date releaseTime;
    /**
     * 是否公开
     */
    private Boolean isPublic = false;
    /**
     * 地点
     */
    private Region place;
    /**
     * 背景图
     */
    private String coverUrl;
    /**
     * 最后更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastUpdateTime;
    /**
     * 状态
     */
    private int state;
    /**
     * 游记内容
     */
    private TravelContent travelContent;

    /**
     * 游记点赞数
     */
    private Integer love=0;
    /**
     * 游记收藏数
     */
    private Integer collectNum = 0;

    public String getStateName() {
        if (state == STATE_DRAFT) {
            return "草稿";
        } else if (state == STATE_PENDING) {
            return "待审核";
        } else if (state == STATE_RELEASE) {
            return "发布";
        } else {
            return "拒绝";
        }
    }

    public String getJson() {
        HashMap<String, Object> map = new HashMap<>(10);
        map.put("id", id);
        map.put("coverUrl", coverUrl);
        map.put("title", title);
        map.put("collectNum", collectNum);
        return JSON.toJSONString(map);
    }

    public String getPersonName() {
        String name = "";
        switch (person) {
            case PERSON_ONE:
                name = "一个人";
                break;
            case PERSON_FM:
                name = "和父母";
                break;
            case PERSON_PY:
                name = "和朋友";
                break;
            case PERSON_TS:
                name = "和同事";
                break;
            case PERSON_AR:
                name = "和爱人";
                break;
            case PERSON_QT:
                name = "其他";
                break;
            default:
                break;
        }
        return name;
    }

}